package com.briup.app02.web.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.briup.app02.bean.BasePrivilege;
import com.briup.app02.bean.BaseRole;
import com.briup.app02.service.IBasePrivilegeService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/baseprivileg")
@Api(description = "权限管理")
public class PrivilegeController {
	@Autowired
    private IBasePrivilegeService baseprivilegeService;
	
	
	@GetMapping("findAll")
	@ApiOperation("查询所有权限信息")
	public Message findAll(){
		List<BasePrivilege> list = baseprivilegeService.findAll();
		return MessageUtil.success(list);
	}
	
	@GetMapping("findByParentId")
	@ApiOperation("根据Parentid查询权限信息")
	public Message findByParentId(Long parentId) {
		List<BasePrivilege> list=baseprivilegeService.findByParentId(parentId);
		return MessageUtil.success(list);
	}
	
	@PostMapping("saveOrUpdate")
	@ApiOperation(value="保存或更新",notes = "id为空是保存否则是更新")
	public Message saveOrUpdate(BasePrivilege baseprivilege) {
		baseprivilegeService.saveOrUpdate(baseprivilege);
		return MessageUtil.success("操作成功");
	}
	
	@GetMapping("deleteById")
	@ApiOperation("根据id删除权限信息")
	@ApiImplicitParam(name="id",value = "权限id",dataType = "long",paramType = "query",required = true)
	public Message deleteById(long id) {
		baseprivilegeService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
}
